import { OperateName } from "./WebDBDefine";

export class WebValueData {
    //列名
    keys: string[] = []
    //值的名称 update 和 insert使用 ，select不会用到
    names: string[] = []
    data: any[] = []
    constructor(operate: string, param: string) {

        switch (operate) {
            //let sqlStr = "SELECT * FROM sqlite_master where type ='table' and name ='" + this.tbName + "'"
            case OperateName.select:
                if (param.indexOf(',') >= 0) {//多个列的情况
                    let list = param.split(',')
                    for (let index = 0; index < list.length; index++) {
                        const element = list[index];
                        this.keys[index] = element.trim()
                    }
                } else {//只查找一列的情况
                    this.keys[0] = param.trim()
                }
                break;
            case OperateName.insert:
                if (param) {
                    let list = param.split(',')
                    // console.log('list ', list)
                    for (let index = 0; index < list.length; index++) {
                        const element = list[index];
                        this.keys.push(element.trim())
                    }
                }
                break;
            case OperateName.update:
                if (param.indexOf(',') >= 0) {//更新多个列
                    let list = param.split(',')
                    for (let index = 0; index < list.length; index++) {
                        const ss = list[index];
                        this.parseUpdate(ss)
                    }
                } else {
                    this.parseUpdate(param)
                }
                break;
            case OperateName.delete:
                break;
        }
    }

    parseUpdate(ss: string) {
        if (ss.indexOf('?') >= 0) {
            let temp = ss.split('=')
            this.keys.push(temp[0].trim())
        } else if (ss.indexOf('@') >= 0) {
            let s = ss.replace(/@/g, '')
            let temp = s.split('=')
            this.keys.push(temp[0].trim())
            this.names.push(temp[1].trim())
        }
    }
}